$(function(){
	
	//登录功能
	$("#login").click(function(){
		var loginName = $("#phoneNo").val();
		var passWord = $("#password").val();
		if (loginName == null || loginName.length == 0) {
			alert("手机号不能为空");
			return false; 
		}
		var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/; 
		if(!myreg.test(loginName)) 
		{ 
		    alert('请输入有效的手机号码！'); 
		    return false; 
		}
		if (passWord == null || passWord.length == 0) {
			alert("密码不能为空");
			 return false; 
		}
		var myreg = /^[0-9A-Za-z]{6,20}$/;   //6-20位数字字母组合
		if(!myreg.test(passWord)) 
		{ 
		    alert('密码为6-20位数字字母组合,请输入有效密码！'); 
		    return false; 
		}
		
		var data = {
						"params": {
							"loginName":loginName,
			       			"passWord":passWord
			   			 }
			   		}
		var jsonData = JSON.stringify(data);
		console.log(jsonData);
		$.ajax({
			url: urlLink+"/bMaMarketCustInfo/login",
			type: "POST",
			contentType: "application/json; charset=utf-8",
			data:jsonData,
			success:function(data){
				if (data.code == "0000") {
					// 跳转到首页
					alert("登录成功");
					var retToken = data.result.receToken;
					var token = retToken.substr(7);  //获取token值
					var qrCode = data.result.qrCode;
					localStorage.setItem("token", token);
					localStorage.setItem("phoneNo", loginName);
					localStorage.setItem("qrCode", qrCode);
					window.location.href = "index.html";

				}else if (data.code == "8900") {
					alert(data.msg);
				}else if (data.code == "8993") {
					alert(data.msg);
				}else if (data.code == "8896") {
					alert(data.msg);
				}else{
					alert(data.msg);
				}
			},
			error: function(data){
				console.log(data);
				alert("服务器繁忙");
			}
		})
	});
	
	//退出功能
	$("#logout").click(function(){
		localStorage.removeItem("token");
		localStorage.removeItem("phoneNo");
		localStorage.removeItem("qrCode");
		window.location.href = "login.html";
	});

})